Lifecycle Events

Scripting supports SwiftUI-style lifecycle hooks onAppear and onDisappear to execute custom logic when a view becomes visible or is removed from the visible interface. These hooks allow you to trigger animations, start data loading, update state, or perform cleanup when views enter or exit the screen.


Property Definitions

1onAppear?: () => void
2onDisappear?: () => void

Property Descriptions

Property Type Description
onAppear () => void Called when the view becomes visible.
onDisappear () => void Called when the view is no longer visible on screen.

Example

1import { VStack, Text, useState } from "scripting"
2
3function Example() {
4  const [message, setMessage] = useState("")
5
6  return <VStack
7    onAppear={() => setMessage("View is visible")}
8    onDisappear={() => setMessage("View is hidden")}
9    padding
10  >
11    <Text>{message}</Text>
12  </VStack>
13}